package org.msfj.admin.data.controller;

import org.msfj.admin.model.MetadataType;
import org.msfj.admin.vo.MetadataTypeVo;
import org.msfj.admin.model.MetadataType;
import org.msfj.admin.vo.MetadataTypeVo;
import org.msfj.admin.model.MetadataType;
import org.msfj.admin.vo.MetadataTypeVo;
import org.msfj.admin.data.service.MetadataTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.msfj.common.base.BaseController;
import org.msfj.common.model.CascaderResult;
import org.msfj.common.model.CommonResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 系统元数据类型controller
 * @Author: like
 * @Email: like@deyatong.com
 * @Date: 2017-08-10 17:30:21
 * @Version: 1.0
 * @Created in idea by autoCode
 */
@Api(value = "系统元数据类型接口", tags = "系统元数据类型接口")
@RestController
@RequestMapping("data/metadataType")
public class MetadataTypeController extends BaseController{

    @Autowired
    private MetadataTypeService metadataTypeService;

    /**
     * 添加系统元数据类型
     *
     * @param metadataTypeVo
     * @return CommonResult.ok(MetadataTypeVo)
     */
    @PostMapping("/add")
    @ResponseBody
    @ApiOperation(value = "添加系统元数据类型",notes = "添加系统元数据类型")
    @ApiImplicitParam(value = "metadataTypeVo",name = "metadataTypeVo",dataType = "org.msfj.admin.vo.MetadataTypeVo",paramType = "query")
    public CommonResult addMetadataType(MetadataTypeVo metadataTypeVo){
        MetadataType metadataType = metadataTypeService.saveOrEdit(metadataTypeVo);
        return CommonResult.ok(metadataTypeService.setOtherProperties(metadataType));
    }

    /**
     * 修改系统元数据类型
     *
     * @param metadataTypeVo
     * @return CommonResult.ok(MetadataTypeVo)
     */
    @PostMapping("/edit")
    @ResponseBody
    @ApiOperation(value = "修改系统元数据类型",notes = "修改系统元数据类型")
    @ApiImplicitParam(value = "metadataTypeVo",name = "metadataTypeVo",dataType = "org.msfj.admin.vo.MetadataTypeVo",paramType = "query")
    public CommonResult editMetadataType(MetadataTypeVo metadataTypeVo){
        MetadataType metadataType = metadataTypeService.saveOrEdit(metadataTypeVo);
        return CommonResult.ok(metadataTypeService.setOtherProperties(metadataType));
    }

    /**
     * 逻辑删除系统元数据类型
     *
     * @param metadataTypeVo
     * @return CommonResult.ok(MetadataTypeVo)
     */
    @PostMapping("/del")
    @ResponseBody
    @ApiOperation(value = "逻辑删除系统元数据类型",notes = "逻辑删除系统元数据类型")
    @ApiImplicitParam(value = "metadataTypeVo",name = "metadataTypeVo",dataType = "org.msfj.admin.vo.MetadataTypeVo",paramType = "query")
    public CommonResult delMetadataType(MetadataTypeVo metadataTypeVo){
        MetadataType metadataType = metadataTypeService.delById(metadataTypeVo);
        return CommonResult.ok(metadataTypeService.setOtherProperties(metadataType));
    }

    /**
     * 逻辑删除系统用户信息
     * @param ids
     * @return CommonResult.ok()
     */
    @PostMapping("/dels")
    @ResponseBody
    @ApiOperation(value = "逻辑删除系统元数据类型",notes = "逻辑删除系统元数据类型")
    @ApiImplicitParam(value = "ids",name = "ids",dataType = "java.util.List",paramType = "query")
    public CommonResult delUsers(@RequestParam(value = "ids[]",required = false) List<String> ids){
        MetadataType metadataType = new MetadataType();
        metadataTypeService.delByIds(ids, metadataType);
        return CommonResult.ok();
    }

    /**
     * 真实删除系统元数据类型
     *
     * @param metadataTypeVo
     * @return CommonResult.ok()
     */
    @PostMapping("/delete")
    @ResponseBody
    @ApiOperation(value = "真实删除系统元数据类型",notes = "真实删除系统元数据类型")
    @ApiImplicitParam(value = "metadataTypeVo",name = "metadataTypeVo",dataType = "org.msfj.admin.vo.MetadataTypeVo",paramType = "query")
    public CommonResult deleteMetadataType(MetadataTypeVo metadataTypeVo){
        metadataTypeService.trueDelById(metadataTypeVo);
        return CommonResult.ok();
    }

    /**
     * 根据id查找系统元数据类型
     *
     * @param metadataTypeVo
     * @return CommonResult.ok(MetadataTypeVo)
     */
    @GetMapping("/get")
    @ResponseBody
    @ApiOperation(value = "根据id查找系统元数据类型",notes = "根据id查找系统元数据类型")
    @ApiImplicitParam(value = "metadataTypeVo",name = "metadataTypeVo",dataType = "org.msfj.admin.vo.MetadataTypeVo",paramType = "query")
    public CommonResult getMetadataType(MetadataTypeVo metadataTypeVo){
        MetadataType metadataType = metadataTypeService.getById(metadataTypeVo.getId());
        return CommonResult.ok(metadataTypeService.setOtherProperties(metadataType));
    }

    /**
     * 根据翻页参数、搜索参数查找系统元数据类型
     *
     * @param metadataTypeVo
     * @param page 当前第几页
     * @param rows 每页多少条记录
     * @return CommonResult.ok(PageInfo<MetadataTypeVo>)
     */
    @GetMapping("/list")
    @ResponseBody
    @ApiOperation(value = "根据翻页参数、搜索参数查找系统元数据类型",notes = "根据翻页参数、搜索参数查找系统元数据类型")
    @ApiImplicitParams({
        @ApiImplicitParam(value = "metadataTypeVo",name = "metadataTypeVo",dataType = "org.msfj.admin.vo.MetadataTypeVo",paramType = "query"),
        @ApiImplicitParam(name = "page",value = "page",dataType = "Integer",paramType = "path"),
        @ApiImplicitParam(name = "rows",value = "rows",dataType = "Integer",paramType = "path")
    })
    public CommonResult findMetadataTypeList(MetadataTypeVo metadataTypeVo, Integer page, Integer rows){
        PageInfo<MetadataTypeVo> metadataTypeVoPageInfo = metadataTypeService.getByMetadataType(metadataTypeVo,page,rows);
        return CommonResult.ok(metadataTypeVoPageInfo);
    }

    /**
     * 根据搜索参数查找所有系统元数据类型
     *
     * @param metadataTypeVo
     * @return CommonResult.ok(List<MetadataTypeVo>)
     */
    @GetMapping("/getAll")
    @ResponseBody
    @ApiOperation(value = "根据搜索参数查找所有系统元数据类型",notes = "根据搜索参数查找所有系统元数据类型")
    @ApiImplicitParam(value = "metadataTypeVo",name = "metadataTypeVo",dataType = "org.msfj.admin.vo.MetadataTypeVo",paramType = "query")
    public CommonResult getAllMetadataType(MetadataTypeVo metadataTypeVo){
        List<MetadataTypeVo> metadataTypeVoList = metadataTypeService.getAllMetadataType(metadataTypeVo);
        return CommonResult.ok(metadataTypeVoList);
    }

    /**
     * 获取系统元数据类型Tree对象
     *
     * @return CommonResult.ok(List<MetadataTypeVo>)
     */
    @GetMapping("/getTree")
    @ResponseBody
    @ApiOperation(value = "获取系统元数据类型Tree对象", notes = "获取系统元数据类型Tree对象")
    public CommonResult getMetadataTypeTree() {
        List<MetadataTypeVo> metadataTypeVos = metadataTypeService.getMetadataTypeTree();
        return CommonResult.ok(metadataTypeVos);
    }

    /**
     * 获取系统元数据类型级联对象
     *
     * @param id  不可选的id
     * @return CommonResult.ok(List<CascaderResult>)
     */
    @GetMapping("/getCascader")
    @ResponseBody
    @ApiOperation(value = "获取系统元数据类型级联对象", notes = "获取系统元数据类型级联对象")
    @ApiImplicitParam(value = "id", name = "id", dataType = "java.lang.Long", paramType = "query")
    public CommonResult getCascader(String id) {
        List<MetadataTypeVo> metadataTypeVos = metadataTypeService.getMetadataTypeTree();
        List<CascaderResult> cascaderResults = CascaderResult.getCascaderResult("Id", "Name", "TreePosition", id, metadataTypeVos);
        return CommonResult.ok(cascaderResults);
    }
}
